<?php
/**
 * ============================================================================
 * Doxt Version: 1.0           
 * Web: http:
 * Copyright (C) 2007 - 2010 Doxt Technology Inc., All Rights Reserved.
 * ---------------------------------------------
 * $Date: 2008.4.8
*/

  if ($_POST["btn_sub"])
  {
    include_once("sub_edit_news.php");
	exit(0);
  }
/* 分类列表文件,显示所有的分类 */
  include("list_cate.php");

  $NEWS_ID = intval( $_GET["id"] );
  if (empty($NEWS_ID)) exit(0);

  $query = "SELECT * FROM $TBL_HOUSE WHERE id='$NEWS_ID'";
  $result = mysql_query( $query ) or die(mysql_error());
  $rows = mysql_fetch_array( $result);
  if($rows['img']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img'];
	$img = "<img src='$file' width='110' /><br>";
  }
  if($rows['img1']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img1'];
	$img1 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=1&img=$rows[img1]'>删除</a><br>";
  }
  if($rows['img2']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img2'];
	$img2 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=2&img=$rows[img2]'>删除</a><br>";
  }
  if($rows['img3']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img3'];
	$img3 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=3&img=$rows[img3]'>删除</a><br>";
  }
  if($rows['img4']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img4'];
	$img4 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=4&img=$rows[img4]'>删除</a><br>";
  }
  if($rows['img5']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img5'];
	$img5 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=5&img=$rows[img5]'>删除</a><br>";
  }
  if($rows['img6']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img6'];
	$img6 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=6&img=$rows[img6]'>删除</a><br>";
  }
  if($rows['img7']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img7'];
	$img7 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=7&img=$rows[img7]'>删除</a><br>";
  }
  if($rows['img8']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img8'];
	$img8 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=8&img=$rows[img8]'>删除</a><br>";
  }
  if($rows['img9']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img9'];
	$img9 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=9&img=$rows[img9]'>删除</a><br>";
  }
  if($rows['img10']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img10'];
	$img10 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=10&img=$rows[img10]'>删除</a><br>";
  }
  if($rows['img11']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img11'];
	$img11 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=11&img=$rows[img11]'>删除</a><br>";
  }
  if($rows['img12']!='')
  {
	$file ='../../upload/house/'.$NEWS_ID."/".$rows['img12'];
	$img12 = "<img src='$file' width='110' />  <a href='delete_pic.php?id=$NEWS_ID&pic_id=12&img=$rows[img12]'>删除</a><br>";
  }
  
  $cate_id = $rows["cate_id"];  //分类id
  $muster = "";
  $level = get_Pro_Parent($muster, $cate_id);  //所有的父类
  if (! empty($level))
  {
    $level = trim(substr($level,1,strlen($level)));
    $arr = explode(",",$level);
	$arr = array_reverse($arr);  //翻转数组
	//动态的创建,显示列表框项

	foreach ($arr as $key => $value)
	{
	  if (0 == $value)
	  {
		  continue;
	  }
	  $i = $key+1;
      $cate_name = get_owner_val("zh_cate_title", "cate_id", $value, $TBL_HOU_CATE);
	  $init_cate .= "create_List(document.all.sel_" .$i . "," . $value . ");\n";
	  $init_cate .= "sel_item(document.all.sel_" . $i . ",'" . $cate_name . "');\n";	
	}
	////选中最后一个列表框项
    $cate_name = get_owner_val("zh_cate_title", "cate_id", $cate_id, $TBL_HOU_CATE);	
	$last_list = count($arr)+1;
    $init_cate .= "sel_item(document.all.sel_" . $last_list . ",'" . $cate_name . "');\n";	
  }
  else  //只有顶级分类 
  {
    $init_cate = "document.getElementById('sel_1').value=$cate_id;";
  }  

  if($rows['ns']==1)   //電梯
  {
	$ns1 = "checked='checked'";
	$ns2 ="";
	$ns3 ="";
  }else if($rows['ns']==2){
	$ns1 = "";
	$ns2 ="checked='checked'";
	$ns3 ="";
  }else{
	$ns1 = "";
	$ns2 = "";
	$ns3 = "checked='checked'";	
  }

  if($rows['unit']=="有")   //車位
  {
	$unit = "checked='checked'";
	$unit2 ="";
	$unit3 ="";	
  }elseif($rows['unit']=="無"){
	$unit = "";
	$unit2 ="checked='checked'";
	$unit3 ="";	
  }else{
	$unit = "";
	$unit2 ="";
	$unit3 ="checked='checked'";	
  
  }

  if($rows['featureday']==1)   //本日精選
  {
	$featureday = "checked='checked'";
	$featureday2 ="";
  }else{
	$featureday = "";
	$featureday2 ="checked='checked'";
  }

  if($rows['feature']==1)
  {
	$feature = "checked='checked'";
	$feature2 ="";
  }else{
	$feature = "";
	$feature2 ="checked='checked'";
  }

  if($rows['saveplan']==0)
  {
	$saveplan = "checked='checked'";
	$saveplan1 ="";
	$saveplan2 ="";
	$saveplan3 ="";
  }elseif($rows['saveplan']==1){
	$saveplan1 = "checked='checked'";
	$saveplan ="";
	$saveplan2 ="";
	$saveplan3 ="";
  }elseif($rows['saveplan']==2){
	$saveplan2 = "checked='checked'";
	$saveplan ="";
	$saveplan1 ="";
	$saveplan3 ="";
  }else{
	$saveplan3 = "checked='checked'";
	$saveplan ="";
	$saveplan1 ="";
	$saveplan2 ="";	
  }

  if($rows['recommended']==1)
  {
	$recommended = "checked='checked'";
	$recommended2 ="";
  }else{
	$recommended = "";
	$recommended2 ="checked='checked'";
  }

  if($rows['del']==0)
  {
	$del1 = "checked='checked'";
	$del2 ="";
  }else{
	$del1 = "";
	$del2 ="checked='checked'";
  }

  $selxx = "select * from $TBL_OPTION order by ord asc";
	$resxx = mysql_query($selxx);
	$jj=0;
	$jd=0;
	$bh=0;
	$gs=0;
	$bq=0;
	while($rowxx = mysql_fetch_array($resxx))
	{
		if($rowxx[type]==1)//類型
		{
            $typexx = $typexx ."<input type=radio name=type value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==2)//電梯
		{
            $elevatorxx = $elevatorxx ."<input type=radio name=elevator value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==3)//家具
		{	
			++$jj;
            $furniturexx = $furniturexx ."<input type=checkbox name=furniture$jj value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==4)//家電
		{	
			++$jd;
            $wiringxx = $wiringxx ."<input type=checkbox name=wiring$jd value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==5)//來源
		{			
            $sourcexx = $sourcexx ."<input type=radio name=source value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==6)//租金包含
		{	
			++$bh;
            $baohangxx = $baohangxx ."<input type=checkbox name=baohang$bh value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==7)//公社
		{	
			++$gs;
            $firexx = $firexx ."<input type=checkbox name=fire$gs value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==8)//保全
		{	
			++$bq;
            $baoquanxx = $baoquanxx ."<input type=checkbox name=baoquan$bq value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==9)//座向
		{	
            $positionxx = $positionxx ."<input type=radio name=position value=$rowxx[title]  >$rowxx[title]";
		}
	}
  
  $selfd = "select * from $TBL_STORE order by id asc"; //分店
  $resultfd = mysql_query($selfd);
  while($rowfd = mysql_fetch_array($resultfd))
  {
		if($rowfd[id]==$rows[store])
	    {
			$selected = "selected";
		}else{
			$selected = '';
		}
		$fd  =$fd."<option value=$rowfd[id]  $selected >$rowfd[name]</option>";
  }
  

  $flo = @explode('/',$rows['floor']);
  //加载FCKeditor编辑器
  include($conf["base_path"] ."fckeditor/fckeditor.php");
  //中文
  $editor = new FCKeditor('tese');
  $editor -> BasePath   = "../../fckeditor/";
  $editor -> ToolbarSet = "Basic";
  $editor -> Width      = "340";
  $editor -> Height     = "200";
  $editor -> Value    = $rows['tese'];
  $tese = $editor->CreateHtml();

  $tpl -> set_file(array("main" => "edit_news.htm"));  
  $tpl -> set_block("main","TYPE_LIST","type_list"); 
  $tpl -> set_var(array(
                         "num"		=> $rows['num'],
						 "source"	=> $rows['source'],
						 "type"		=> $rows['type'],
						 "area"		=> $rows['area'],
						 "tel"		=> $rows['tel'],
						 "linkman"	=> $rows['linkman'],
						 "address"	=> $rows['address'],
						 "price"	=> $rows['price'],
						 "sale"		=> $rows['sale'],
						 "min_sale" => $rows['min_sale'],
						 "deposit"  => $rows['deposit'],
						 "layout"	=> $rows['layout'],
						 "floor"	=> $rows['floor'],	
						 "flo1"	=> $flo[0],		
						 "flo2"	=> $flo[1],	
						 "wiring"	=> $rows['wiring'],
						 "furniture"=> $rows['furniture'],
						 "fire"		=> $rows['fire'],
						 "position" => $rows['position'],
						 "age"      => $rows['age'],
						 "title"    => $rows['title'],
						 "baoquan"    => $rows['baoquan'],
						 "hou_name"    => $rows['hou_name'],
						 "elevator"    => $rows['elevator'],
						 "adminshow"    => $rows['adminshow'],
						 "tese"    => $tese,
						 "baohang"    => $rows['baohang'],
						 "map"    => $rows['map'],
						 "mobile"    => $rows['mobile'],
						 "adminnotes"    => $rows['adminnotes'],
						  


						 "featureday"  => $featureday,
						 "featureday2" => $featureday2,

						 "ns1"  => $ns1,
						 "ns2" => $ns2,
						 "ns3" => $ns3,

						 "del1" => $del1,
						 "del2" => $del2,

						 "feature"	=> $feature,
						 "feature2" => $feature2,

						 "saveplan" => $saveplan,		
						 "saveplan1"=> $saveplan1,
						 "saveplan2"=> $saveplan2,		
						 "saveplan3"=> $saveplan3,


						 "recommended"	=> $recommended,		
						 "recommended2" => $recommended2,

						 "unit"	 => $unit,		
						 "unit2" => $unit2,
						 "unit3" => $unit3,								
						
						 "id"=> $rows['id'],
						
						 "check".$rows['sorting']=>"checked='checked'",
                         "SHOW_CATE" => $show_cate,
	     				
						 "NEWS_ID" => $NEWS_ID,
						 "init_cate" => $init_cate,						 

						 "img" => $img,
						 "img1" => $img1,
						 "img2" => $img2,
						 "img3" => $img3,
						 "img4" => $img4,
						 "img5" => $img5,
						 "img6" => $img6,
						 "img7" => $img7,
						 "img8" => $img8,
						 "img9" => $img9,
						 "img10" => $img10,
						 "img11" => $img11,
						 "img12" => $img12,

						 "typexx" => $typexx,
						 "furniturexx" => $furniturexx,
						 "wiringxx" => $wiringxx,
						 "firexx" => $firexx,
						 "positionxx" => $positionxx,
						 "baohangxx" => $baohangxx,
						 "baoquanxx" => $baoquanxx,
						 "elevatorxx" => $elevatorxx,
						 "sourcexx" => $sourcexx,

						 "fd" => $fd,	 
						
                       ));
  $tpl -> set_var( $conf);
  $tpl -> parse("Output", "main");
  $tpl -> p("Output");
  exit(0);
?>